package com.itheima.service.impl;

import com.itheima.mapper.ItemGroupDao;
import com.itheima.mapper.SetmealAndItemGroupDao;
import com.itheima.mapper.SetmealDao;
import com.itheima.pojo.Setmeal;
import com.itheima.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SetmealServiceImpl implements SetmealService {

    @Autowired
    private SetmealDao setmealDao;

    @Autowired
    private ItemGroupDao itemGroup;

    @Autowired
    private SetmealAndItemGroupDao setmealAndItemGroup;
    // 查询套餐
    @Override
    public List<Setmeal> getSetmeal() {
        return setmealDao.getAllSetmealList();
    }

    // 根据id查询套餐
    // 查询套餐中关联的检查组
    @Override
    public Setmeal findById(Integer id) {
        Setmeal setmeal = setmealDao.findById(id);
        if (setmeal != null) {
            List<Integer> checkGroupIds = setmealAndItemGroup.getCheckGroupIdsBySetmealId(id);
            setmeal.setCheckGroups(itemGroup.findByIds(checkGroupIds));
        }
        return setmeal;
    }
}
